package com.example.springbootsocketclient1.config;

import com.example.springbootsocketclient1.socket.MyWebSocketClient;
import org.java_websocket.client.WebSocketClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.URI;
import java.net.URISyntaxException;

@Configuration
public class WebSocketClientConfig {
    private final String wsServerUrl = "ws://127.0.0.1:8881/websocket/user1";

    @Bean
    public WebSocketClient webSocketClient(){
        try{
            MyWebSocketClient webSocketClient = new MyWebSocketClient(new URI(wsServerUrl));
            webSocketClient.connect();
            return webSocketClient;
        }catch (URISyntaxException e){
            return null;
        }
    }
}
